<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
    <script src="https://cdn.bootcss.com/vue-router/3.1.3/vue-router.min.js"></script>
</head>
<body>
    <div id="app">
        <router-link to="/t1?a=123&b=111&c=haha">go to t1</router-link>
        <router-link to="/t2/55/andy/23">go to t2</router-link>

        <router-view></router-view>
    </div>
    <template id="t1">
        <div>
            组件1 !!
            {{this.$route.query.a}}
            <button @click="f1">go</button>
        </div>
    </template>
    <template id="t2">
        <div>
            组件2
            {{this.$route.params.id}} <br>
            {{this.$route.params.name}} <br>
            {{this.$route.params.age}} <br>
        </div>
    </template>
    <script>

        var t1 = {
            template: "#t1",
            methods: {
                f1() {

                    // this.$route.query可以获取到当前路径中的"?"后面的字符串，也就是“查询字符串”
                    console.log(this.$route.query.c);
                    
                }
            }
        };

        var t2 = {
            template: "#t2"
        };

        var router = new VueRouter({
            routes: [
                {component:t1, path:"/t1"},    
                {component:t2, path:"/t2/:id/:name/:age"}  
            ]
        });

        var app = new Vue({
            el: "#app",
            data: {
                msg: "aaa"
            },
            router 
        });
    </script>
</body>
</html>